home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 7 / Apprentice-Release7.iso / Environments / Clean 1.2.4 / IOInterface / deltaPicture.dcl < prev    next >
Encoding:
Modula Definition  |  1997-02-06  |  9.4 KB  |  244 lines  |  [TEXT/3PRM]

  1. definition module deltaPicture;
  2.  
  3.  
  4. //    Version 0.8 to 1.0
  5.  
  6. //
  7. //    Drawing functions and other operations on Pictures. 
  8. //
  9.  
  10. import deltaFont;
  11.  
  12. /*
  13. ::    *Picture;
  14.  
  15. ::    DrawFunction    -> => Picture Picture;
  16.  
  17. ==    Predefined figures:
  18.  
  19. ::    Point                -> (!INT, !INT);
  20. ::    Line                -> (!Point, !Point);
  21. ::    Curve                -> (!Oval, !INT, !INT);
  22. ::    Rectangle        -> (!Point, !Point);
  23. ::    RoundRectangle    -> (!Rectangle, !INT, !INT);
  24. ::    Oval                -> Rectangle;
  25. ::    Circle            -> (!Point, !INT);
  26. ::    Wedge                -> (!Oval, !INT, !INT);
  27. ::    Polygon            -> (!Point, !PolygonShape);
  28.  
  29. ::    PolygonShape    -> [Vector];
  30. ::    Vector            -> (!INT, !INT);
  31.  
  32. ==    The pen attributes which influence the way figures are drawn:
  33.  
  34. ::    PenSize        -> (!INT, !INT);
  35. ::    PenMode        -> CopyMode        | OrMode            | XorMode        |
  36.                         ClearMode    | HiliteMode    | NotCopyMode    |
  37.                         NotOrMode    | NotXorMode    | NotClearMode;
  38. ::    PenPattern    -> BlackPattern    |    DkGreyPattern    | GreyPattern |
  39.                         LtGreyPattern    |    WhitePattern;
  40.  
  41. ==    The predefined colours:
  42.  
  43. ::    Colour    -> RGB REAL REAL REAL
  44.                 |    BlackColour    | RedColour
  45.                 |    WhiteColour    | GreenColour
  46.                 |    BlueColour    | YellowColour
  47.                 |    CyanColour    | MagentaColour;
  48.  
  49. MACRO
  50.     MinRGB -> 0.0;
  51.     MaxRGB -> 1.0;
  52.  
  53. RULE
  54.     
  55. <<    Rules setting the attributes of a Picture:
  56. >>
  57.  
  58. <<    SetPenSize (w, h) sets the PenSize to w pixels wide and h pixels high.
  59.     SetPenMode sets the drawing mode of the pen.
  60.     SetPenPattern sets the pattern of the pen.
  61.     SetPenNormal sets the SetPenSize to (1,1), the PenMode to CopyMode and
  62.         the PenPattern to BlackPattern. >>
  63.  
  64. ::    SetPenSize        !PenSize        !Picture -> Picture;
  65. ::    SetPenMode        !PenMode        !Picture -> Picture;
  66. ::    SetPenPattern    !PenPattern    !Picture -> Picture;
  67. ::    SetPenNormal                    !Picture -> Picture;
  68.  
  69. <<    Colour: There are two types of Colours: RGB colours and basic colours.
  70.     An RGB colour defines the amount of red (r), green (g) and blue (b)
  71.     in a certain colour by the tuple (r,g,b). These are REAL values and
  72.     each of them must be between MinRGB and MaxRGB (0.0 and 1.0).
  73.     The colour black is defined by (MinRGB, MinRGB, MinRGB) and white
  74.     by (MaxRGB, MaxRGB, MaxRGB). Given a RGB colour, all amounts are
  75.     adjusted between MinRGB and MaxRGB.
  76.     Only FullColour windows can apply RGB colours. Applications that use
  77.     these windows may not run on all computers (e.g. Macintosh Plus).
  78.     A small set of basic colours is defined that can be used on all systems.
  79.     SetPenColour    sets the colour of the pen.
  80.     SetBackColour    sets the background colour. >>
  81.  
  82. ::    SetPenColour    !Colour !Picture -> Picture;
  83. ::    SetBackColour    !Colour !Picture -> Picture;
  84.  
  85. <<    Fonts: The initial font of a Picture is the DefaultFont (See
  86.            deltaFont.dcl). On the Macintosh the default font is
  87.            plain 12 points Geneva.
  88.     SetFont         sets a new complete Font in the Picture.
  89.     SetFontName     sets a new font without changing the style or size.
  90.     SetFontStyle sets a new style without changing font or size. An
  91.                  empty list of FontStyle gives the plain style.
  92.     SetFontSize     sets a new size without changing font or style.
  93.                      The size is always adjusted between MinFontSize and
  94.                      MaxFontSize (see deltaFont.dcl). >>
  95.  
  96. ::    SetFont            !Font                !Picture -> Picture;
  97. ::    SetFontName        !FontName        !Picture -> Picture;
  98. ::    SetFontStyle    ![FontStyle]    !Picture -> Picture;
  99. ::    SetFontSize        !FontSize        !Picture -> Picture;
  100.  
  101. <<    PictureCharWidth   (PictureStringWidth) yield the width of the given
  102.                        CHAR (STRING) given the current font of the Picture.
  103.     PictureFontMetrics yields the FontInfo of the current font. >>
  104.  
  105. ::    PictureCharWidth     !CHAR    !Picture -> (!INT,        !Picture);
  106. ::    PictureStringWidth !STRING !Picture -> (!INT,        !Picture);
  107. ::    PictureFontMetrics            !Picture -> (!FontInfo, !Picture);
  108.  
  109. <<    Rules changing the position of the pen:
  110. >>
  111.  
  112. <<    Absolute and relative pen move operations (without drawing). >>
  113.  
  114. ::    MovePenTo    !Point  !Picture -> Picture;
  115. ::    MovePen        !Vector !Picture -> Picture;
  116.  
  117. <<    Absolute and relative pen move operations (with drawing). >>
  118.  
  119. ::    LinePenTo    !Point  !Picture -> Picture;
  120. ::    LinePen        !Vector !Picture -> Picture;
  121.  
  122. <<    DrawChar (DrawString) draws the character (string) in the current font.
  123.     The baseline of the characters is the y coordinate of the pen.
  124.     The new position of the pen is directly after the (last) character
  125.     (of the string). >>
  126.  
  127. ::    DrawChar        !CHAR        !Picture -> Picture;
  128. ::    DrawString    !STRING    !Picture -> Picture;
  129.  
  130. <<    Rules that don't change the position of the pen after drawing:
  131. >>
  132.  
  133. <<    Draw(C)Point    draws a pixel (in the given colour) in the Picture.
  134.     Draw(C)Line        draws a line  (in the given colour) in the Picture.
  135.     Draw(C)Curve    draws a curve (in the given colour) in the Picture.
  136.         A Curve is part of an Oval o starting from angle a upto
  137.         angle b (both of type INT in degrees modulo 360): (o, a, b).
  138.         See Wedges for further information on the angles. >>
  139.  
  140. ::    DrawPoint    !Point    !Picture -> Picture;
  141. ::    DrawLine        !Line        !Picture -> Picture;
  142. ::    DrawCurve    !Curve    !Picture -> Picture;
  143. ::    DrawCPoint    !Point !Colour !Picture -> Picture;
  144. ::    DrawCLine    !Line     !Colour !Picture -> Picture;
  145. ::    DrawCCurve    !Curve !Colour !Picture -> Picture;
  146.  
  147. <<    A Rectangle is defined by two diagonal corner Points.
  148.     DrawRectangle        draws the edges of the rectangle.
  149.     FillRectangle        draws the edges and interior of the rectangle.
  150.     EraseRectangle        erases the edges and interior of the rectangle.
  151.     InvertRectangle    inverts the edges and interior of the rectangle.
  152.     MoveRectangleTo    moves the contents of the rectangle to a new top corner.
  153.     MoveRectangle        moves the contents of the rectangle over the given vector.
  154.     CopyRectangleTo    copies the contents of the rectangle to a new top corner.
  155.     CopyRectangle        copies the contents of the rectangle over the given vector. >>
  156.  
  157. ::    DrawRectangle        !Rectangle !Picture -> Picture;
  158. ::    FillRectangle        !Rectangle !Picture -> Picture;
  159. ::    EraseRectangle        !Rectangle !Picture -> Picture;
  160. ::    InvertRectangle    !Rectangle !Picture -> Picture;
  161. ::    MoveRectangleTo    !Rectangle !Point        !Picture -> Picture;
  162. ::    MoveRectangle        !Rectangle !Vector    !Picture -> Picture;
  163. ::    CopyRectangleTo    !Rectangle !Point        !Picture -> Picture;
  164. ::    CopyRectangle        !Rectangle !Vector    !Picture -> Picture;
  165.  
  166. <<    Rounded corner rectangles: a RoundRectangle with enclosing Rectangle
  167.     r and corner curvatures x and y is defined by the tuple (r, x, y).
  168.     x and y define the horizontal and vertical diameter of the corner curves.
  169.     They are adjusted between 0 and the width (height) of r. >>
  170.  
  171. ::    DrawRoundRectangle    !RoundRectangle !Picture -> Picture;
  172. ::    FillRoundRectangle    !RoundRectangle !Picture -> Picture;
  173. ::    EraseRoundRectangle    !RoundRectangle !Picture -> Picture;
  174. ::    InvertRoundRectangle    !RoundRectangle !Picture -> Picture;
  175.  
  176. <<    Ovals: an Oval is defined by its enclosing Rectangle.
  177.     Note : the Oval of a square Rectangle is a Circle. >>
  178.  
  179. ::    DrawOval        !Oval !Picture -> Picture;
  180. ::    FillOval        !Oval !Picture -> Picture;
  181. ::    EraseOval    !Oval !Picture -> Picture;
  182. ::    InvertOval    !Oval !Picture -> Picture;
  183.  
  184. <<    Circles:    a Circle with center c (Point) and radius r (INT) is
  185.     defined by the tuple (c, r). >>
  186.  
  187. ::    DrawCircle        !Circle !Picture -> Picture;
  188. ::    FillCircle        !Circle !Picture -> Picture;
  189. ::    EraseCircle        !Circle !Picture -> Picture;
  190. ::    InvertCircle    !Circle !Picture -> Picture;
  191.  
  192. <<    Wedges: a Wedge is a pie-part of an Oval o starting from angle a
  193.     upto angle b (both of type INT in degrees modulo 360): (o, a, b).
  194.     Angles are always taken counterclockwise, starting from 3 o'clock. >>
  195.  
  196. ::    DrawWedge    !Wedge !Picture -> Picture;
  197. ::    FillWedge    !Wedge !Picture -> Picture;
  198. ::    EraseWedge    !Wedge !Picture -> Picture;
  199. ::    InvertWedge    !Wedge !Picture -> Picture;
  200.  
  201. <<    A Polygon is a number of consecutive points between which lines are drawn.
  202.     The starting point of the Polygon is also the end point. The PolygonShape
  203.     is a list of vectors that defines the shape of the Polygon.
  204.     ScalePolygon    scales (reduces, enlarges) the Polygon. Non-postive scale
  205.                    factors are allowed.
  206.     MovePolygonTo    changes the starting point into the given Point.
  207.     MovePolygon        moves the starting point by the given Vector. >>
  208.  
  209. ::    ScalePolygon    !INT        !Polygon -> Polygon;
  210. ::    MovePolygonTo    !Point    !Polygon -> Polygon;
  211. ::    MovePolygon        !Vector    !Polygon -> Polygon;
  212. ::    DrawPolygon        !Polygon !Picture    -> Picture;
  213. ::    FillPolygon        !Polygon !Picture    -> Picture;
  214. ::    ErasePolygon    !Polygon !Picture    -> Picture;
  215. ::    InvertPolygon    !Polygon !Picture    -> Picture;
  216. */
  217.  
  218. from Picture import
  219.     Picture, DrawFunction,
  220.     Point, Line, Curve, Rectangle, RoundRectangle,
  221.     Oval, Circle, Wedge, Polygon, PolygonShape, Vector,
  222.     PenSize,
  223.     PenMode,
  224.         CopyMode, OrMode, XorMode, ClearMode, HiliteMode,
  225.         NotCopyMode, NotOrMode, NotXorMode, NotClearMode,
  226.     PenPattern, BlackPattern, DkGreyPattern, GreyPattern, LtGreyPattern, WhitePattern,
  227.     Colour, RGB, MinRGB, MaxRGB,
  228.         BlackColour, RedColour, WhiteColour, GreenColour,
  229.         BlueColour, YellowColour, CyanColour, MagentaColour,
  230.     SetPenSize, SetPenMode, SetPenPattern, SetPenNormal, SetPenColour, SetBackColour,
  231.     SetFont,SetFontName, SetFontStyle, SetFontSize,
  232.         PictureCharWidth, PictureStringWidth, PictureFontMetrics,
  233.     MovePenTo, MovePen, LinePenTo, LinePen,
  234.     DrawChar, DrawString,
  235.     DrawPoint, DrawLine, DrawCurve, DrawCPoint, DrawCLine, DrawCCurve,
  236.     CopyRectangleTo, CopyRectangle, MoveRectangleTo, MoveRectangle,
  237.     DrawRectangle,            FillRectangle,            EraseRectangle,            InvertRectangle,
  238.     DrawRoundRectangle,        FillRoundRectangle,        EraseRoundRectangle,    InvertRoundRectangle,
  239.     DrawOval,                FillOval,                EraseOval,                InvertOval,
  240.     DrawCircle,                FillCircle,                EraseCircle,            InvertCircle,
  241.     DrawWedge,                FillWedge,                EraseWedge,                InvertWedge,
  242.     DrawPolygon,            FillPolygon,            ErasePolygon,            InvertPolygon,
  243.     ScalePolygon, MovePolygonTo, MovePolygon;
  244.